package cn.Mmovie.service.impl;

import cn.Mmovie.bean.Auditorium;
import cn.Mmovie.bean.Schedule;
import cn.Mmovie.dao.Impl.ScheduleDaoImpl;
import cn.Mmovie.dao.ScheduleDao;
import cn.Mmovie.service.ScheduleService;
import cn.Mmovie.util.PageUtil;

import java.time.LocalDateTime;
import java.util.Date;

public class ScheduleServiceImpl implements ScheduleService {
    private ScheduleDao scheduleDao=new ScheduleDaoImpl();
    @Override
    public PageUtil<Schedule> page(Integer pageNo, Integer pageSize) {
        PageUtil<Schedule> pageUtil = new PageUtil<>();
        pageUtil.setPageNo(pageNo);
        pageUtil.setPageSize(pageSize);
        pageUtil.setRecordCount(scheduleDao.selectForRecordTotal());
        pageUtil.setItems(scheduleDao.selectForPageItems((pageUtil.getPageNo() - 1) * pageUtil.getPageSize(), pageUtil.getPageSize()));
        pageUtil.setUrl("/admin/cinema_list?pageSize=" + pageUtil.getPageSize());
        return pageUtil;
    }

    @Override
    public Integer addSchedule(Schedule schedule) {
        Integer result=-1;
        if (scheduleDao.selectById(schedule.getId())==null){
            result= scheduleDao.insert(schedule);
        }
        return result;
    }

    @Override
    public Integer modifySchedule(Schedule schedule) {
        Integer result=-1;
        if (scheduleDao.selectById(schedule.getId())!=null){
            result=scheduleDao.update(schedule);
        }
        return result;
    }

    @Override
    public Schedule queryById(Integer id) {
        return scheduleDao.selectById(id);
    }

    @Override
    public Integer deleteScheduleById(Integer id) {
        Integer result=-1;
        if (scheduleDao.selectById(id)!=null){
            result=scheduleDao.delete(id);
        }
        return result;
    }
}
